package leetcode;

import java.util.Stack;

/**
 * Created by MtRider on 2021/10/16 13:30
 */
public class StackPushPop {
    public static void main(String[] args) {
        String s = "{[]}";
        boolean valid = isValid(s);
        System.out.println(valid);
    }

    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        for (char aChar : chars) {
            if (aChar == '(') {
                stack.push(')');
            }else if (aChar == '[') {
                stack.push(']');
            }else if (aChar == '{') {
                stack.push('}');
            }else if(stack.isEmpty() || aChar!=stack.pop()){
                return false;
            }

        }
        return stack.isEmpty();

    }
}
